/**
 * @Created by 
 * @updated by
 * @description 批量重跑方案管理
 */
define(function (require, exports) {
	/**
	 * 页面加载完成时触发
	 * @param hashCode 路由ID
	 * @param data 传递数据对象
	 * @param cite 页面站点信息
	 */
	exports.ready = function (hashCode, data, cite) {
		yufp.lookup.reg('USE_SCHEME_VALID,USE_EVT_REL_TYPE,USE_TASK_TRIGGER_TYPE');
		yufp.custom.vue({
			el: cite.el,
			data: function () {
				var _this = this;
				return {
					// 权限控制
					routerList:[],
					routerDialog:false,
					taskSelectedList:[],
					tbHeight:'0',
					addFnShow: !yufp.session.checkCtrl('addFnShow'),
					modifyFnShow: !yufp.session.checkCtrl('modifyFnShow'),
					deleteFnShow: !yufp.session.checkCtrl('deleteFnShow'),
					runFnShow: !yufp.session.checkCtrl('runFnShow'),
					monitorFnShow: !yufp.session.checkCtrl('monitorFnShow'),
					// 数据对象
					searchFormdata: {},
					viewTitle: "",
					cycleTime: [],
					updateFormData: {},
					taskInfos: [],
					searchTaskFormdata: {},
					queryJobFormData: {},
					jobSelectedData: [],
					taskSelected: {},
					runFormData: {},
					// 数据展示
					dataUrl: "api/use/app/jobRedo/queryList",
					taskDataUrl: "api/use/plats/taskSchedule/queryList",
					jobDataUrl: "api/use/app/jobRedo/jobQueryList",
					wftRunDataUrl: "api/use/monitor/taskMonitor/queryList",
					// 页面属性
					showLoading: false,
					updateLoading: false,
					updateDialog: false,
					isNew: false,
					taskChooseDialog: false,
					jobChooseDialog: false,
					jobChooseDialogOld: false,
					runDialog: false,
					taskFieldDatas: [
						{ placeholder: '系统名称', field: 'appName', type: 'input' },
						{ placeholder: '系统代码', field: 'appCode', type: 'input' },
						{ placeholder: '任务名称', field: 'taskName', type: 'input' }
					],
					taskButtons: [
						{
							label: '搜索',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								var param = { condition: JSON.stringify(model) };
								_this.$refs.taskTableRef.remoteData(param);
							}
						}, {
							label: '确定',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								var selectArr = _this.$refs.taskTableRef.selections;
								for (var sel in selectArr) {
									var flag = true;
									for (var ins in _this.taskInfos) {
										if (selectArr[sel].taskId == _this.taskInfos[ins].taskId) {
											flag = false;
										}
									}
									if (flag) {
										_this.taskInfos.push(selectArr[sel]);
									}
								}
								_this.taskChooseDialog = false;
							}
						}
					],
					taskFieldColumns: [
						{ label: "系统名称", prop: "appName" },
						{ label: "任务名称", prop: "taskName" },
						{ label: "任务路径", prop: "folderPath" },
						{ label: "触发类型", prop: "triggerType", dataCode: "USE_TASK_TRIGGER_TYPE" },
						{ label: "工作日历", prop: "calendarName" },
						{ label: "生效日期", prop: "effectDate" },
						{ label: "失效日期", prop: "expireDate" },
						{ label: "任务状态", prop: "validFlag", dataCode: "USE_TASK_STATE" }
					],
					jobFieldDatas: [
						// { placeholder: '应用系统', field: 'appCode', type: 'input', disabled: true },
						// { placeholder: '作业流', field: 'groupCode', type: 'input', disabled: true },
						{ placeholder: '作业名称', field: 'actionName', type: 'input' }
					],
					jobButtons: [
						{
							label: '搜索',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								model.appCode = _this.queryJobFormData.appCode;
								model.groupCode = _this.queryJobFormData.groupCode;
								var param = { condition: JSON.stringify(model) };
								_this.$refs.jobTableRef.remoteData(param);
							}
						}, {
							label: '选中',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								//var data = _this.$refs.jobTableRef.tabledata;
								var data = _this.$refs.jobTableRef.selections;
								data = data.map( item => {
									item.runFlag = 'Y';
									return item;
								})
								for (var j in data) {
									var flag = true;
									for (var i in _this.jobSelectedData) {
										if (data[j].appCode == _this.jobSelectedData[i].appCode 
											&& data[j].groupCode == _this.jobSelectedData[i].groupCode 
											&& data[j].actionCode == _this.jobSelectedData[i].actionCode) {
											flag = false;	
										}
									}
									if (flag) {
										_this.jobSelectedData.push(data[j]);
									}
								}
								_this.taskSelected.jobSelecteds = _this.jobSelectedData;
								_this.taskSelected.actionCount = _this.jobSelectedData.length;
								//_this.$refs.jobTableRef.remoteData();
							}
						}, {
							label: '反选',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								//var data = _this.$refs.jobTableRef.tabledata;
								var data = _this.$refs.jobTableRef.selections;
								data = data.map( item => {
									item.runFlag = 'N';
									return item;
								})
								var newjobSelectedData = [];
								for (var i in _this.jobSelectedData) {
									var flag = false;
									for (var j in data) {
										if (data[j].appCode == _this.jobSelectedData[i].appCode 
											&& data[j].groupCode == _this.jobSelectedData[i].groupCode 
											&& data[j].actionCode == _this.jobSelectedData[i].actionCode) {
											flag = true;
											break;
										}
									}
									if (!flag) {
										newjobSelectedData.push(_this.jobSelectedData[i]);
									}
								}
								_this.jobSelectedData = newjobSelectedData;
								_this.taskSelected.jobSelecteds = newjobSelectedData;
								_this.taskSelected.actionCount = newjobSelectedData.length;
								//_this.taskSelected.jobSelecteds = _this.jobSelectedData;
								//_this.$refs.jobTableRef.remoteData();
							}
						}, {
							label: '确定',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								//_this.taskSelected.jobSelecteds = _this.jobSelectedData;
								_this.jobChooseDialog = false;
							}
						}
					],
					jobButtonsOld: [//taskSelectedList
						 {
							label: '选中',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								var taskSelectedListOld = _this.taskSelectedList ||[];//原来的
								var taskSelectedList = _this.$refs.jobTableRefOld.selections;//需要选中的
								taskSelectedList = taskSelectedList.map( item => {
									item.runFlag = 'Y';
									return item;
								});
								var newsel = [];
								for(var i in taskSelectedListOld){
									 var fg = false;
									 for(var j in taskSelectedList){
										   if (taskSelectedList[j].appCode == taskSelectedListOld[i].appCode
										   	&& taskSelectedList[j].groupCode == taskSelectedListOld[i].groupCode 
										   	&& taskSelectedList[j].actionCode == taskSelectedListOld[i].actionCode) {
										   	flag = true;
										   	break;
										   }
									 }
									 if(flag){
										 taskSelectedListOld[i].runFlag = 'Y';
									 }		
									 if(taskSelectedListOld[i].runFlag == 'Y'){
										 newsel.push(taskSelectedListOld[i]);
									 }
								}									
								_this.taskSelectedList = taskSelectedListOld;
								_this.jobSelectedData = newsel;
								_this.taskSelected.jobSelecteds = newsel;
								_this.taskSelected.actionCount = newsel.length;
							}
						}, {
							label: '反选',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								var taskSelectedListOld = _this.taskSelectedList ||[];//原来的
								var taskSelectedList = _this.$refs.jobTableRefOld.selections;//需要去掉选中的
								taskSelectedList = taskSelectedList.map( item => {
									item.runFlag = 'N';
									return item;
								});
								var newsel = [];
								for(var i in taskSelectedListOld){
									 var fg = false;
									 for(var j in taskSelectedList){
										   if (taskSelectedList[j].appCode == taskSelectedListOld[i].appCode
										   	&& taskSelectedList[j].groupCode == taskSelectedListOld[i].groupCode 
										   	&& taskSelectedList[j].actionCode == taskSelectedListOld[i].actionCode) {
										   	flag = true;
										   	break;
										   }
									 }
									 if(flag){
										 taskSelectedListOld[i].runFlag = 'N';
									 }		
									 if(taskSelectedListOld[i].runFlag == 'Y'){
										 newsel.push(taskSelectedListOld[i]);
									 }
								}									
								_this.taskSelectedList = taskSelectedListOld;
								_this.jobSelectedData = newsel;
								_this.taskSelected.jobSelecteds = newsel;
								_this.taskSelected.actionCount = newsel.length;			
							}
						},{
							label: '确定',
							op: 'submit',
							type: 'primary',
							click: function (model, valid) {
								//_this.taskSelected.jobSelecteds = _this.taskSelectedList;
								_this.jobChooseDialogOld = false;
							}
						}
					],
					runState: [
						{ key: true, value: '运行中' },
						{ key: false, value: '未运行' }
					],
					runStateStr: [
						{ key: "Y", value: '运行中' },
						{ key: 'N', value: '未运行' }
					],
					schemeCodeRules: [
						{ required: true, message: '该项不能为空', trigger: 'blur' },
						{ max: 64, message: '输入值过长', trigger: 'blur' }
					],
					schemeNameRules: [
						{ required: true, message: '该项不能为空', trigger: 'blur' },
						{ max: 120, message: '输入值过长', trigger: 'blur' }
					]
				};
			},
			mounted:function(){
				var _this = this;
				//测试
				_this.$nextTick(function(){
						var tableBox = _this.$refs.tableBox;
						let a = tableBox.getBoundingClientRect().top + 28;
						var theight = `calc(100vh - ${a}px - 64px)`;
						_this.tbHeight = theight;		
				});
			},
			methods: {
				// 重新加载表数据
				reload: function () {
					var _this = this;
					var param = { condition: JSON.stringify(_this.searchFormdata) };
					_this.$refs.refTable.remoteData(param);
				},
				// 新增
				addFn: function () {
					var _this = this;
					_this.viewTitle = "新增重跑方案";
					_this.taskInfos.splice(0);
					_this.updateDialog = true;
					_this.isNew = true;
					//_this.updateFormData = {};
					_this.$nextTick(function () {
						_this.$refs.updateForm.resetFields();
						_this.cycleTime.splice(0);
					})
				},
				// 修改
				modifyFn: function () {
					var _this = this;
					var selections = _this.$refs.refTable.selections;
					console.info(selections);
					if (selections.length == 1) {
						//判断该条是否在运行，运行中的不让修改
						if(selections[0].runState){
							_this.$message({ message: '任务运行中，无法修改!', type: "warning", duration: 4000 });
							return;
						}
						_this.viewTitle = "修改重跑方案";
						_this.updateDialog = true;
						_this.isNew = false;
						_this.$nextTick(function () {
							// 基础属性
							yufp.clone(selections[0], _this.updateFormData);
							// 数组属性
							// taskInfos
							if(_this.updateFormData.taskInfos) {
								_this.updateFormData.taskInfos.splice(0);
								yufp.clone(selections[0].taskInfos, _this.updateFormData.taskInfos);
							} else {
								yufp.clone(selections[0].taskInfos, _this.updateFormData.taskInfos);
							}
							// useSchemeDataActions
							if(_this.updateFormData.useSchemeDataActions) {
								_this.updateFormData.useSchemeDataActions.splice(0);
								yufp.clone(selections[0].useSchemeDataActions, _this.updateFormData.useSchemeDataActions);
							} else {
								yufp.clone(selections[0].useSchemeDataActions, _this.updateFormData.useSchemeDataActions);
							}
							// useSchemeDataTasks
							if(_this.updateFormData.useSchemeDataTasks) {
								_this.updateFormData.useSchemeDataTasks.splice(0);
								yufp.clone(selections[0].useSchemeDataTasks, _this.updateFormData.useSchemeDataTasks);
							} else {
								yufp.clone(selections[0].useSchemeDataTasks, _this.updateFormData.useSchemeDataTasks);
							}
							// 周期时点间隔
							_this.cycleTime.splice(0);
							_this.cycleTime.push(_this.updateFormData.beginTime);
							_this.cycleTime.push(_this.updateFormData.endTime);
							_this.updateFormData.cycleTime = _this.cycleTime;
							// 任务列表
							_this.taskInfos.splice(0);
							_this.taskInfos = _this.taskInfos.concat(_this.updateFormData.useSchemeDataTasks);
						});
					} else {
						_this.$message({ message: '请先选择一条记录', duration: 6000 });
					}
				},
				// 删除
				deleteFn: function () {
					var _this = this;
					var selections = _this.$refs.refTable.selections;
					if (selections.length > 0) {
						//判断该条是否在运行，运行中的不让修改
						for (var i in selections) {
							if(selections[i].runState){
								_this.$message({ message: '存在运行中任务，无法删除!', type: "warning", duration: 4000 });
								return;
							}
						}
						_this.showLoading = true;
						yufp.service.request({
							method: 'POST',
							url: "api/use/app/jobRedo/deleteInfo",
							data: JSON.stringify(selections),
							callback: function (code, message, response) {
								_this.showLoading = false;
								if (response.code == 0) {
									_this.$message({ message: "操作成功", type: "info" });
									_this.reload();
								} else {
									_this.$message({ message: "操作失败:" + response.message, type: "error" });
								}
							}
						});
					} else {
						_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
					}
				},
				// 运行
				runFn: function () {
					var _this = this;
					var selections = _this.$refs.refTable.selections;
					if (selections.length == 1 && selections[0].validFlag == 'Y') {
						_this.showLoading = true;
						yufp.service.request({
							method: 'POST',
							timeout: 1800000,
							url: "api/use/app/jobRedo/schemeRun",
							data: JSON.stringify(selections[0]),
							callback: function (code, message, response) {
								_this.showLoading = false;
								if (response.code == 0) {
									_this.$message({ message: "操作成功", type: "info" });
									_this.reload();
								} else {
									_this.$message({ message: "操作失败:" + response.message, type: "error" });
								}
							}
						});
					} else {
						_this.$message({ message: '请选择一条生效记录', type: 'warning', duration: 6000 });
					}
				},
				// 监控
				monitorFn: function () {
					var _this = this;
					var selections = _this.$refs.refTable.selections;
					if (selections.length == 1) {
						var rowData = selections[0];
						if (rowData.runState) {
							var customKey = 'custom_' + rowData.schemeCode;
							var routeId = 'router_' + rowData.schemeCode;
							var url = 'pages/use/apps/jobRedoManager/jobRedoMonitor';
							yufp.router.addRoute(routeId, {
								html: url + '.html',
								js: url + '.js'
							});
							rowData.runFnShow = _this.runFnShow;
							yufp.frame.addTab({
								id: routeId, // 菜单功能ID（路由ID）
								key: customKey, // 自定义唯一页签key,请统一使用custom_前缀开头
								title: '方案[' + rowData.schemeName + ']运行监控', // 页签名称
								data: yufp.clone({ routeId: routeId, title: '方案[' + rowData.schemeName + ']运行监控' }, rowData)// 传递的业务数据，可选配置
							});
						} else {
							_this.$message({ message: '该方案未执行', type: 'warning', duration: 6000 });
						}
					} else {
						_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
					}
				},
				// 修改生效标志
				updateFlag: function (row) {
					var _this = this;
					_this.showLoading = true;
					yufp.service.request({
						method: 'POST',
						url: "api/use/app/jobRedo/updateInfo",
						data: row,
						callback: function (code, message, response) {
							_this.showLoading = false;
							if (response.code == 0) {
								_this.$message({ message: "操作成功", type: "info" });
							} else {
								row.validFlag = row.validFlag == "Y" ? "N" : "Y";
								_this.$message({ message: "处理失败", type: "error" });
							}
						}
					});
				},
				// 保存作业重跑方案
				saveJobRedoPlan: function () {
					var _this = this;
					var validate = false;
					_this.$refs.updateForm.validate(function (valid) {
						validate = valid;
					});
					if (!validate) {
						return;
					}
					if (_this.updateFormData.beginTime == null || _this.updateFormData.endTime == null || 
						_this.updateFormData.beginTime == '' || _this.updateFormData.endTime == '') {
						_this.$message({ message: "请选择周期时点范围", type: "warning" });
					} else {
						if (_this.taskInfos.length > 0) {
							_this.updateFormData.taskInfos = _this.taskInfos;
							for (var i in _this.updateFormData.taskInfos) {
								if (!_this.updateFormData.taskInfos[i].jobSelecteds || _this.updateFormData.taskInfos[i].jobSelecteds.length== 0) {
									_this.$message({ message: "存在任务未选择作业", type: "warning" });
									return;
								}
							}
							console.info(_this.updateFormData);
							_this.updateLoading = true;
							_this.updateFormData.isNew = _this.isNew;
							yufp.service.request({
								method: 'POST',
								url: "api/use/app/jobRedo/saveInfo",
								data: JSON.stringify(_this.updateFormData),
								callback: function (code, message, response) {
									_this.updateLoading = false;
									if (response.code == 0) {
										_this.updateDialog = false;
										_this.$message({ message: "操作成功", type: "info" });
										_this.reload();
									} else {
										_this.$message({ message: "操作失败:" + response.message, type: "error" });
									}
								}
							});
						} else {
							_this.$message({ message: "请至少选择一个任务", type: "warning" });
						}
					}
				},
				// 任务选择页面
				taskSelect: function () {
					var _this = this;
					_this.taskChooseDialog = true;
					_this.$nextTick(function () {
						_this.$refs.taskTableRef.clearSelection();
						_this.$refs.queryTaskForm.$children[0].resetFields();
						var param = { condition: JSON.stringify({}) };
						_this.$refs.taskTableRef.remoteData(param);
					});
				},
				// 时间选择器变化处理
				daterangeChange: function () {
					var _this = this;
					_this.updateFormData.beginTime = '';
					_this.updateFormData.endTime = '';
					if (_this.cycleTime && _this.cycleTime.length > 1) {
						_this.updateFormData.beginTime = _this.cycleTime[0];
						_this.updateFormData.endTime = _this.cycleTime[1];
					}
				},
				jobSelectOld:function(row){//作业已选页面
					 var _this = this;
					 _this.taskSelected = row;
					 var sel= row.jobSelecteds || [];
					 sel = sel.map( item => {
						 item.runFlag = 'Y'
						 return item;
					 })
					_this.taskSelectedList = sel || [];
					_this.jobChooseDialogOld = true;
					
				},
				// 作业选择页面
				jobSelect: function (row) {
					var _this = this;
					_this.queryJobFormData.appCode = row.appCode;
					_this.queryJobFormData.groupCode = row.groupCode;
					_this.taskSelected = row;
					_this.jobChooseDialog = true;
					// 先清除选择内容
					_this.jobSelectedData = _this.taskSelected.jobSelecteds ? _this.taskSelected.jobSelecteds : [];
					_this.$nextTick(function () {
						var param = { condition: JSON.stringify(_this.queryJobFormData) };
						_this.$refs.jobTableRef.remoteData(param);
						_this.$refs.queryJobForm.$children[0].resetFields();
					});
				},
				// 依赖任务查询
				depjobSelect: function (row) {
					console.info(row);
					var _this = this;
					row.searchType = "D";
					if (row.jobSelecteds && row.jobSelecteds.length > 0) {
						_this.updateLoading = true;
						yufp.service.request({
							method: 'POST',
							url: "api/use/app/jobRedo/searchTaskRel",
							data: JSON.stringify(row),
							callback: function (code, message, response) {
								if (response.code === 0) {
									for (var i in response.data) {
										var flag = true;
										for (var ins in _this.taskInfos) {
											if (response.data[i].appCode == _this.taskInfos[ins].appCode &&
												response.data[i].groupCode == _this.taskInfos[ins].groupCode) {
												flag = false;
												for (var j in response.data[i].jobSelecteds) {
													if (_this.taskInfos[ins].jobSelecteds.findIndex(item => {
														return item.actionCode == response.data[i].jobSelecteds[j].actionCode;
													}) == -1) {
														_this.taskInfos[ins].jobSelecteds.push(response.data[i].jobSelecteds[j]);
														_this.taskInfos[ins].actionCount = _this.taskInfos[ins].jobSelecteds.length;
													}
												}
											}
										}
										if (flag) {
											_this.taskInfos.push(response.data[i]);
										}
									}
									_this.$message({ message: "查询上游成功", type: 'info' });
								} else {
									_this.$message({ message: response.message, type: 'error', showClose: true, duration: 0 });
								}
								_this.updateLoading = false;
							}
						});
					} else {
						_this.$message({ message: '请先选择任务包含的作业', type: 'warning', duration: 6000 });
					}
				},
				// 触发任务查询
				triggerjobSelect: function (row) {
					var _this = this;
					row.searchType = "T";
					if (row.jobSelecteds && row.jobSelecteds.length > 0) {
						_this.updateLoading = true;
						yufp.service.request({
							method: 'POST',
							url: "api/use/app/jobRedo/searchTaskRel",
							data: JSON.stringify(row),
							callback: function (code, message, response) {
								if (response.code === 0) {
									for (var i in response.data) {
										var flag = true;
										for (var ins in _this.taskInfos) {
											if (response.data[i].appCode == _this.taskInfos[ins].appCode &&
												response.data[i].groupCode == _this.taskInfos[ins].groupCode) {
												flag = false;
												for (var j in response.data[i].jobSelecteds) {
													if (_this.taskInfos[ins].jobSelecteds.findIndex(item => {
														return item.actionCode == response.data[i].jobSelecteds[j].actionCode;
													}) == -1) {
														_this.taskInfos[ins].jobSelecteds.push(response.data[i].jobSelecteds[j]);
														_this.taskInfos[ins].actionCount = _this.taskInfos[ins].jobSelecteds.length;
													}
												}
											}
										}
										if (flag) {
											_this.taskInfos.push(response.data[i]);
										}
									}
									_this.$message({ message: "查询下游成功", type: 'info' });
								} else {
									_this.$message({ message: response.message, type: 'error', showClose: true, duration: 0 });
								}
								_this.updateLoading = false;
							}
						});
					} else {
						_this.$message({ message: '请先选择任务包含的作业', type: 'warning', duration: 6000 });
					}
				},
				// 内容下游
				innerTriggerjobSelect: function (row) {
					var _this = this;
					row.searchType = "T";
					if (row.jobSelecteds && row.jobSelecteds.length > 0) {
						_this.updateLoading = true;
						yufp.service.request({
							method: 'POST',
							url: "api/use/app/jobRedo/searchJobRel",
							data: JSON.stringify(row),
							callback: function (code, message, response) {
								if (response.code === 0) {
									var routerList = [];
									for (var i in response.data) {
										var taskName = '';
										var count = 0;
										var flag = true;
										for (var ins in _this.taskInfos) {
											if (response.data[i].appCode == _this.taskInfos[ins].appCode &&
												response.data[i].groupCode == _this.taskInfos[ins].groupCode) {
												flag = false;
												for (var j in response.data[i].jobSelecteds) {
													if (_this.taskInfos[ins].jobSelecteds.findIndex(item => {
														return item.actionCode == response.data[i].jobSelecteds[j].actionCode;
													}) == -1) {
														count = count + 1;
														_this.taskInfos[ins].jobSelecteds.push(response.data[i].jobSelecteds[j]);
														_this.taskInfos[ins].actionCount = _this.taskInfos[ins].jobSelecteds.length;
													}
												}
											}
										}
										if(count > 0){
											routerList.push({'taskName':response.data[i].taskName,'count':count});
										}
										if (flag) {
											_this.taskInfos.push(response.data[i]);
											routerList.push({'taskName':response.data[i].taskName,'count':response.data[i].jobSelecteds.length});
										}
									}
									 _this.routerList = routerList;
									 _this.routerDialog = true;
									_this.$message({ message: "查询下游成功", type: 'info' });
								} else {
									_this.$message({ message: response.message, type: 'error', showClose: true, duration: 0 });
								}
								_this.updateLoading = false;
							}
						});
					} else {
						_this.$message({ message: '请先选择任务包含的作业', type: 'warning', duration: 6000 });
					}
				},
				// 外部下游
				outerTriggerjobSelect: function (row) {
					var _this = this;
					row.searchType = "T";
					if (row.jobSelecteds && row.jobSelecteds.length > 0) {
						_this.updateLoading = true;
						yufp.service.request({
							method: 'POST',
							url: "api/use/app/jobRedo/searchTaskRel",
							data: JSON.stringify(row),
							callback: function (code, message, response) {
								if (response.code === 0) {
									var routerList = [];
									for (var i in response.data) {
										var taskName = '';
										var count = 0;
										var flag = true;
										for (var ins in _this.taskInfos) {
											if (response.data[i].appCode == _this.taskInfos[ins].appCode &&
												response.data[i].groupCode == _this.taskInfos[ins].groupCode) {
												flag = false;
												for (var j in response.data[i].jobSelecteds) {
													if (_this.taskInfos[ins].jobSelecteds.findIndex(item => {
														return item.actionCode == response.data[i].jobSelecteds[j].actionCode;
													}) == -1) {
														count = count + 1;
														_this.taskInfos[ins].jobSelecteds.push(response.data[i].jobSelecteds[j]);
														_this.taskInfos[ins].actionCount = _this.taskInfos[ins].jobSelecteds.length;
													}
												}
											}
										}
										if(count > 0){
											routerList.push({'taskName':response.data[i].taskName,'count':count});
										}
										if (flag) {
											_this.taskInfos.push(response.data[i]);
											routerList.push({'taskName':response.data[i].taskName,'count':response.data[i].jobSelecteds.length});
										}
									}
									_this.routerList = routerList;
									_this.routerDialog = true;
									_this.$message({ message: "查询下游成功", type: 'info' });
								} else {
									_this.$message({ message: response.message, type: 'error', showClose: true, duration: 0 });
								}
								_this.updateLoading = false;
							}
						});
					} else {
						_this.$message({ message: '请先选择任务包含的作业', type: 'warning', duration: 6000 });
					}
				},
				// 双击选择任务
				chooseTask: function (row, event) {
					var _this = this;
					_this.taskInfos.push(row);
					_this.taskChooseDialog = false;
				},
				// 任务移除
				taskRemove: function () {
					var _this = this;
					var selections = _this.$refs.refTaskTable.selections;
					if (selections.length > 0) {
						for (var sel in selections) {
							_this.taskInfos.splice(_this.taskInfos.indexOf(selections[sel]), 1);
						}
					} else {
						_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
					}
				},
				// 作业选择
				chooseJob: function (row) {
					var _this = this;
					if (_this.taskSelected.actionCount == null) {
						_this.taskSelected.actionCount = 0;
					}
					if (row.runFlag === "Y") {
						_this.jobSelectedData.push(row);
						_this.taskSelected.actionCount = _this.jobSelectedData.length;
						_this.taskSelected.jobSelecteds = _this.jobSelectedData;
					} else {
						for (var i in _this.jobSelectedData) {
							if (_this.jobSelectedData[i].appCode == row.appCode && _this.jobSelectedData[i].groupCode == row.groupCode 
								&& _this.jobSelectedData[i].actionCode == row.actionCode) {
								_this.jobSelectedData.splice(_this.jobSelectedData.indexOf(_this.jobSelectedData[i]), 1);
								_this.taskSelected.actionCount = _this.jobSelectedData.length;
							}
						}
						//_this.jobSelectedData.splice(_this.jobSelectedData.indexOf(row), 1);
						//_this.taskSelected.actionCount = _this.jobSelectedData.length;
						_this.taskSelected.jobSelecteds = _this.jobSelectedData;
					}
				},
				chooseJobOld: function (row) {
					var _this = this;
					var taskSelectedList = _this.taskSelectedList || [];
					var arr = [];
					var oldsel = _this.jobSelectedData || [];
				   if (row.runFlag == "N") {
					   for (var i in oldsel) {
					   	if (oldsel[i].appCode == row.appCode && oldsel[i].groupCode == row.groupCode 
					   		&& oldsel[i].actionCode == row.actionCode) {
					   		oldsel.splice(oldsel.indexOf(oldsel[i]), 1);
					   		//_this.taskSelected.actionCount = oldsel.length;
					   	}
					   }
						//oldsel.splice(oldsel.indexOf(row), 1);
					}else{
						oldsel.push(row);
					}
					_this.jobSelectedData = oldsel;
					_this.taskSelected.jobSelecteds = oldsel;
					_this.taskSelected.actionCount = oldsel.length;
					console.log(_this.jobSelectedData);
				},
				// 作业列表选中反显处理
				jobListLoaded: function (data, total) {
					var _this = this;
					for (var i in data) {
						for (var j in _this.jobSelectedData) {
							if (_this.jobSelectedData[j].actionCode == data[i].actionCode) {
								data[i].runFlag = "Y";
								data[i].relation = _this.jobSelectedData[j].relation;
								data[i].relActionCode = _this.jobSelectedData[j].relActionCode;
								data[i].relActionName = _this.jobSelectedData[j].relActionName;
							}
						}
					}
				},
				cellClick: function (row, event, column, index) {
					var _this = this;
					if (row) {
						_this.$refs.refTable.toggleRowSelection(row);
					}
				}
			}
		});
	};
});